home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games 1996 July / Amiga Games 1996 #7.iso / spiele / publicdomain / ta-hack / source / ta-hack.c < prev    next >
C/C++ Source or Header  |  1996-04-22  |  6KB  |  249 lines

  1. /* Libraries */
  2. #include <libraries/mui.h>
  3.  
  4. /* protos */
  5. #include <clib/muimaster_protos.h>
  6. #include <clib/alib_protos.h>
  7. #include <clib/dos_protos.h>
  8. #include <clib/exec_protos.h>
  9.  
  10. /*  Pragmas  */
  11. #include <pragmas/muimaster_pragmas.h>
  12. #include <pragmas/exec_pragmas.h>
  13.  
  14. /*  Ansi  */
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <math.h>
  18. #include <dos.h>
  19.  
  20. struct Library *MUIMasterBase;
  21. struct DosLibrary *DOSBase;
  22.  
  23. char err[2*FAULT_MAX];
  24.  
  25. /* MUIBuilder */
  26. #include "GUI.h"
  27. #include "Hack.c"
  28. #include "LS.c"
  29.  
  30. #define about_txt "\033c\
  31. \033bTowerAssault Hack\033n\n\n\
  32. This little Programm was programmed\n\
  33. by \033bALeX Kazik\033n. It´s FreeWare. Soure\n\
  34. Code is avaiable. Read TFM for usage.\n\
  35. \n\
  36. Contact me:\n\
  37. akazik@TechFak.Uni-Bielefeld.DE\n\
  38. \n\
  39. or\n\
  40. \n\
  41. AleX Kazik\n\
  42. Stapenhorststr. 81\n\
  43. 33615 Bielefeld\n\
  44. GERMANY"
  45.  
  46. #define minmax(MIN,a,MAX) min(max(MIN,a),MAX)
  47.  
  48. /* titel */
  49. static void title(void){
  50.     printf("TA-Hack V1.0 ©1996 ALeX Kazik\n");
  51. }
  52.  
  53. /* Init function */
  54. static int init(char *argv0){
  55.     if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN))){
  56.         title();
  57.         printf("%s: Can't Open MUIMaster Library\n",argv0);
  58.         return(FALSE);
  59.     }
  60.     return(TRUE);
  61. }
  62.  
  63. /* main-gui function */
  64. BOOL running = TRUE;
  65. static int main_gui(char *argv0, BOOL force){
  66.     struct ObjApp * App; /* Application object */
  67.     ULONG    signal, plr;
  68.     APTR aboutwin = NULL;
  69.  
  70.     /* Program initialisation ( you need to write it yourself) */
  71.     if(!init(argv0))
  72.         return(20);
  73.  
  74.     /* Create Application : generated by MUIBuilder */
  75.     if(!(App = CreateApp())){
  76.         CloseLibrary(MUIMasterBase);
  77.         return(20);
  78.     }
  79.  
  80.     /* Init */
  81.     set(App->TX_STATUS, MUIA_Text_Contents, findTA());
  82.     
  83.     if(found==0 || (found>2 && !force))
  84.         set(App->GRP_PLAYER, MUIA_Disabled, TRUE);
  85.     else{
  86.         set(App->STR_LIVES, MUIA_String_Integer, *LIVES[0]);
  87.         set(App->STR_MONEY, MUIA_String_Integer, *MONEY[0]);
  88.         set(App->CY_PLAYER, MUIA_Cycle_Active, 0);
  89.     }
  90.     
  91.     if(found==0 || found>=4 || (found==3 && !force))
  92.         set(App->GRP_LS, MUIA_Disabled, TRUE);
  93.  
  94.     while (running){
  95.         switch (DoMethod(App->App,MUIM_Application_Input,&signal)){
  96.         case MUIV_Application_ReturnID_Quit:
  97.             running = FALSE;
  98.             break;
  99.         case ID_LIVES:
  100.             get(App->CY_PLAYER, MUIA_Cycle_Active, &plr);
  101.             setlives(plr, App->STR_LIVES);
  102.             set(App->WINDOW, MUIA_Window_ActiveObject, App->STR_MONEY);
  103.             break;
  104.         case ID_MONEY:
  105.             get(App->CY_PLAYER, MUIA_Cycle_Active, &plr);
  106.             set(App->CY_PLAYER, MUIA_Cycle_Active, 1-plr);
  107.             break;
  108.         case ID_PLAYER:
  109.             get(App->CY_PLAYER, MUIA_Cycle_Active, &plr);
  110.             setlives(1-plr, App->STR_LIVES);
  111.             setmoney(1-plr, App->STR_MONEY);
  112.             set(App->STR_LIVES, MUIA_String_Integer, *LIVES[plr]);
  113.             set(App->STR_MONEY, MUIA_String_Integer, *MONEY[plr]);
  114.             set(App->WINDOW, MUIA_Window_ActiveObject, App->STR_LIVES);
  115.             break;
  116.         case ID_PAGES:
  117.             get(App->GRP_PAGES, MUIA_Group_ActivePage, &plr);
  118.             if(plr == 1)
  119.                 set(App->WINDOW, MUIA_Window_ActiveObject, App->STR_LIVES);
  120.             break;
  121.         case ID_ABOUT_MUI:
  122.             if (!aboutwin){
  123.                 aboutwin = AboutmuiObject,
  124.                     MUIA_Window_RefWindow, App->WINDOW,
  125.                     MUIA_Aboutmui_Application, App->App,
  126.                     End;
  127.             }
  128.             if (aboutwin)
  129.                 set(aboutwin,MUIA_Window_Open,TRUE);
  130.             else
  131.                 DisplayBeep(0);
  132.             break;
  133.         case ID_ABOUT:
  134.             MUI_RequestA(App->App, App->WINDOW, NULL, NULL, "*OK", about_txt, NULL);
  135.             break;
  136.         case ID_SAVE:
  137.             sprintf(err+FAULT_MAX, "\0332%s", Save(App->GA_STATUS));
  138.             set(App->GA_STATUS, MUIA_Gauge_InfoText, err+FAULT_MAX);
  139.             break;
  140.         case ID_LOAD:
  141.             sprintf(err+FAULT_MAX, "\0332%s", Load(force,App->GA_STATUS));
  142.             set(App->GA_STATUS, MUIA_Gauge_InfoText, err+FAULT_MAX);
  143.             break;
  144.         }
  145.         if (running && signal)
  146.             if (Wait(signal | SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
  147.                 running = FALSE;
  148.     }
  149.     get(App->CY_PLAYER, MUIA_Cycle_Active, &plr);
  150.     setlives(plr, App->STR_LIVES);
  151.     setmoney(plr, App->STR_MONEY);
  152.     DisposeApp(App);
  153.     CloseLibrary(MUIMasterBase);
  154.     return(0);
  155. }
  156.  
  157. /* brk-function*/
  158. static int brkfunc(void){
  159.     running = FALSE;
  160.     return(0);
  161. }
  162.  
  163. /* Arguments */
  164. char ArgStr[] = "PL1LIVES/N,PL2LIVES/N,MONEY/N,LOAD/S,SAVE/S,FILE=NAME/K,MUI=GUI/S,FORCE/S";
  165. struct {
  166.     LONG *PL1LIVES, *PL2LIVES, *MONEY;
  167.     LONG LOAD, SAVE;
  168.     char *NAME;
  169.     LONG GUI, FORCE;
  170. } ArgArray = {NULL, NULL, NULL, NULL};
  171.  
  172. static char *setORnot(LONG *a){
  173.     return(a?" (set)":"");
  174. }
  175.  
  176. /* Main */
  177. int main(int argc, char **argv){
  178.     struct RDArgs *rda;
  179.     int ret = 20;
  180.  
  181.     if(onbreak(brkfunc)){
  182.         title();
  183.         printf("%s: Could´nt install break trap.\n",argv[0]);
  184.         return(20);
  185.     }
  186.  
  187.     DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37L);
  188.     if(!DOSBase){
  189.         title();
  190.         printf("%s: Could´nt open dos.library V37.\n",argv[0]);
  191.         return(20);
  192.     }
  193.  
  194.     if(argc == 0)
  195.         ret=main_gui(argv[0],FALSE);
  196.     else if(!(rda = ReadArgs(ArgStr, (LONG *)&ArgArray, NULL))){
  197.         dummy = IoErr();
  198.         title();
  199.         PrintFault(dummy,argv[0]);
  200.     }else{
  201.         if(ArgArray.NAME)
  202.             savefile = ArgArray.NAME;
  203.         if(ArgArray.GUI)
  204.             ret=main_gui(argv[0], ArgArray.FORCE);
  205.         else{
  206.             title();
  207.             printf("%s: %s\n",argv[0],findTA());
  208.             if(found != 0){
  209.                 if(ArgArray.LOAD){
  210.                     if(found >= 4)
  211.                         printf("%s: Do´nt know, how to load.\n",argv[0]);
  212.                     else if(found == 3 && !ArgArray.FORCE)
  213.                         printf("%s: Programm unidentified. (Try FORCE)\n",argv[0]);
  214.                     else
  215.                         printf("%s: %s\n",argv[0],Load(ArgArray.FORCE,NULL));
  216.                 }
  217.                 if(found>2 && !ArgArray.FORCE)
  218.                     printf("%s: Programm unidentified. (Try FORCE)\n",argv[0]);
  219.                 else{
  220.                     if(ArgArray.PL1LIVES)
  221.                         *LIVES[0] = minmax(0,*ArgArray.PL1LIVES,99);
  222.                     if(ArgArray.PL2LIVES)
  223.                         *LIVES[1] = minmax(0,*ArgArray.PL2LIVES,99);
  224.                     if(ArgArray.MONEY)
  225.                         *MONEY[0] = *MONEY[1] = minmax(0,*ArgArray.MONEY,999999);
  226.                 }
  227.                 printf("Player1: %d Lives%s\n",*LIVES[0],setORnot(ArgArray.PL1LIVES));
  228.                 printf("         %d CR%s\n",*MONEY[0],setORnot(ArgArray.MONEY));
  229.                 printf("Player2: %d Lives%s\n",*LIVES[1],setORnot(ArgArray.PL1LIVES));
  230.                 printf("         %d CR%s\n",*MONEY[1],setORnot(ArgArray.MONEY));
  231.                 if(ArgArray.SAVE){
  232.                     if(found >= 4)
  233.                         printf("%s: Do´nt know, how to save.\n",argv[0]);
  234.                     else if(found == 3 && !ArgArray.FORCE)
  235.                         printf("%s: Programm unidentified. (Try FORCE)\n",argv[0]);
  236.                     else
  237.                         printf("%s: %s\n",argv[0],Save(NULL));
  238.                 }
  239.                 ret=0;
  240.             }
  241.         }
  242.         FreeArgs(rda);
  243.     }
  244.     
  245.     CloseLibrary((struct Library *) DOSBase);
  246.     
  247.     return(ret);
  248. }
  249.